﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CubicFWNet.Data.Models;
using CubicFWNet.Data.ViewModal;

namespace CubicFWNet.Data.SystemManager
{
    public class FinanceInvoiceRepository : RepositoryBase<FinanceInvoice>
    {
        public IQueryable<InvoiceView> GetFinanceInvoicesList(int status, string orderNumber)//, DateTime beginTime, DateTime endTime
        {
            var result = from fice in dbcontext.FinanceInvoices
                         join order in dbcontext.Orders
                         on fice.OrderId equals order.Id
                         join customer in dbcontext.Customers
                         on order.CustomeId equals customer.Id
                         where (string.IsNullOrEmpty(orderNumber) || order.CusNumber.Contains(orderNumber))
                         && (fice.Status == status || status == -10)
                         //&& (order.CreateTime >= beginTime && order.CreateTime <= endTime)
                         select new InvoiceView
                         {
                             Id = fice.Id,
                             OrderId = order.Id,
                             OrderStatus = order.Status,
                             OrderNumber = order.Number,
                             CreateTime = order.CreateTime,
                             CreatorName = customer.Name,
                             Status = fice.Status,
                             OwnTime = fice.ApplyTime,
                             CusNumber = order.CusNumber
                         };

            return result;
        }

    }
}
